package com.zhangbo.service.imp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhangbo.dao.UserMapper;
import com.zhangbo.entity.User;
import com.zhangbo.service.UserService;
import com.zhangbo.utils.CmsContant;
import com.zhangbo.utils.CmsUtils;

@Service
public class UserServiceImp implements UserService{

	@Autowired
	UserMapper umap;

	@Override
	public int register(User user) {
		// TODO Auto-generated method stub
		user.setPassword(CmsUtils.md5Encrytype(user.getPassword(), user.getUname()));
		return umap.add(user);
	}

	@Override
	public User findByName(String uname) {
		// TODO Auto-generated method stub
		return umap.findByName(uname);
	}

	@Override
	public User login(User user) {
		// TODO Auto-generated method stub
		User name = findByName(user.getUname());
		String encrytype = CmsUtils.md5Encrytype(user.getPassword(), user.getUname());
		if(name != null && encrytype.equals(name.getPassword())) {
			return name;
		}
		return null;
	}

	@Override
	public PageInfo<User> list(int page) {
		// TODO Auto-generated method stub
		PageHelper.startPage(page, CmsContant.PAGE_SIZE);
		return new PageInfo<User>(umap.list());
	}

	@Override
	public int Lock(int userid, int status) {
		// TODO Auto-generated method stub
		return umap.updateLocked(userid, status);
	}
	
	
}
